package com.ling.design.impl;

import com.ling.design.ICouponDiscount;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author: ling007
 * @date: 2024/9/27 14:24
 * @description:
 */

public class MJCouponDiscount implements ICouponDiscount<Map<String,String>> {

    /**
     * 满减计算
     * 1. 判断满⾜足x元后-n元，否则不不减
     * 2. 最低⽀支付⾦金金额1元
     */
    @Override
    public BigDecimal discountAmount(Map<String,String> couponInfo,
                                     BigDecimal skuPrice) {
        String x = couponInfo.get("x");
        String o = couponInfo.get("n");
        // ⼩小于商品⾦金金额条件的，直接返回商品原价
        if (skuPrice.compareTo(new BigDecimal(x)) < 0) return skuPrice;
        // 减去优惠⾦金金额判断
        BigDecimal discountAmount = skuPrice.subtract(new BigDecimal(o));
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) return
                BigDecimal.ONE;
        return discountAmount;
    }
}
